package com.meeting.meeting.controller;

import com.github.pagehelper.PageInfo;
import com.meeting.meeting.model.Room;
import com.meeting.meeting.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author 何星霖
 * @date 2019/1/31 17:54
 */
@Controller
public class RoomController {
    @Autowired
    RoomService roomService;
    @RequestMapping("/getAllroom")
    public String getAllroom(Room room, ModelMap model,
                             @RequestParam(required=true,value="pageNum",defaultValue="1") Integer pageNum,
                             @RequestParam(required=true,value="pageSize",defaultValue="10") Integer pageSize){
        model.put("room",room);
        PageInfo<Room> pageInfo = roomService.selectAll(pageNum,pageSize,room);
        List<Room> list=pageInfo.getList();
        long count=pageInfo.getTotal();
        model.put("roomList",list);
        model.put("pageInfo",pageInfo);
        model.put("count",count);
        return "pages/room";
    }
    @RequestMapping("/deletroom")
    public String delete(Integer id,ModelMap model){
        int a=roomService.deleteByPrimaryKey(id);
        if (a>0){
            model.put("type","room");
            return "pages/delete";
        }else {
            model.put("tips","过程出现不安定因素，请重试!");
            return "pages/505";
        }
    }
    @RequestMapping("/getroombyid")
    public String getroombyid(@RequestParam(required=true,value="id") Integer id,ModelMap model){
        Room room=roomService.selectByPrimaryKey(id);
        model.put("room",room);
        return "pages/roomedit";
    }
    @RequestMapping("/editroom")
    public String editroom(ModelMap model, Room room){
        int a=roomService.updateByPrimaryKey(room);
        if (a>0){
            model.put("type","room");
            return "pages/update";
        }else {
            model.put("tips","过程出现不安定因素，请重试!");
            return "505";
        }
    }
    @RequestMapping("/newroom")
    public String newroom(ModelMap model, Room room){
        int a=roomService.insert(room);
        if (a>0){
            model.put("type","room");
            return "pages/new";
        }else {
            model.put("tips","过程出现不安定因素，请重试!");
            return "505";
        }
    }
    @RequestMapping("/tonewroom")
    public String tonewroom(ModelMap model, Room room){
        return "pages/roomnew";
    }
}
